/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.example.anan.AAChartCore.expandablelist;

/**
 * BaseExpandableItemProvider
 *
 * @author author
 * @version 1.0
 */
public abstract class BaseExpandableItemProvider implements ExpandableItemProvider,
        TypeExpandableListContainer {
    private final DataSetObservable mDataSetObservable = new DataSetObservable();

    /**
     * addDataSetObserver
     *
     * @param observer observer
     */
    public void addDataSetObserver(DataSetObserver observer) {
        mDataSetObservable.addObserver(observer);
    }

    /**
     * removeDataSetObserver
     *
     * @param observer observer
     */
    public void removeDataSetObserver(DataSetObserver observer) {
        mDataSetObservable.removeObserver(observer);
    }

    /**
     * notifyDataSetInvalidated
     */
    public void notifyDataSetInvalidated() {
        mDataSetObservable.notifyInvalidated();
    }

    /**
     * notifyDataSetChanged
     */
    public void notifyDataSetChanged() {
        mDataSetObservable.notifyChanged();
    }

    /**
     * areAllItemsEnabled
     *
     * @return boolean
     */
    public boolean areAllItemsEnabled() {
        return true;
    }

    /**
     * onGroupCollapsed
     *
     * @param groupPosition groupPosition
     */
    public void onGroupCollapsed(int groupPosition) {
    }

    /**
     * onGroupExpanded
     *
     * @param groupPosition groupPosition
     */
    public void onGroupExpanded(int groupPosition) {
    }

    /**
     * getCombinedChildId
     *
     * @param groupId groupId
     * @param childId childId
     * @return long
     */
    public long getCombinedChildId(long groupId, long childId) {
        return 0x8000000000000000L | ((groupId & 0x7FFFFFFF) << 32) | (childId & 0xFFFFFFFF);
    }

    /**
     * getCombinedGroupId
     *
     * @param groupId groupId
     * @return long
     */
    public long getCombinedGroupId(long groupId) {
        return (groupId & 0x7FFFFFFF) << 32;
    }

    /**
     * isEmpty
     *
     * @return boolean
     */
    public boolean isEmpty() {
        return getGroupCount() == 0;
    }


    /**
     * getChildType
     *
     * @param groupPosition groupPosition
     * @param childPosition childPosition
     * @return int
     */
    public int getChildType(int groupPosition, int childPosition) {
        return 0;
    }

    /**
     * getChildTypeCount
     *
     * @return int
     */
    public int getChildTypeCount() {
        return 1;
    }

    /**
     * getGroupType
     *
     * @param groupPosition groupPosition
     * @return int
     */
    public int getGroupType(int groupPosition) {
        return 0;
    }

    /**
     * getGroupTypeCount
     *
     * @return int
     */
    public int getGroupTypeCount() {
        return 1;
    }
}
